package com.fancy.learncenter.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.fancy.learncenter.activity.base.BaseActivity;
import com.fancy.learncenter.bean.BaseDataBean;
import com.fancy.learncenter.bean.UserAccountDataBean;
import com.fancy.learncenter.net.HttpMehtod;
import com.fancy.learncenter.net.IdeaObserver;
import com.superservice.lya.R;

import java.util.HashMap;
import java.util.Map;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class WalletActivity extends BaseActivity {

    @Bind(R.id.title)
    TextView title;
    @Bind(R.id.my_account)
    TextView myAccount;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_wallet, getResources().getColor(R.color.toolbar_color));
        ButterKnife.bind(this);
        initToolbar("我的钱包");
        setRight("交易明细", new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(WalletActivity.this, PayFlowActivity.class);
                startActivity(intent);
            }
        });
    }

    @OnClick({R.id.back, R.id.reflect, R.id.chongzhi})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.reflect:
                Intent intent = new Intent(this, ReflectMoneyActivity.class);
                intent.putExtra("totalMoney", "" + totalMoney);
                startActivity(intent);
                break;
            case R.id.back:
                finish();
                break;
            case R.id.chongzhi:
//                totalMoney
                startActivity(new Intent(WalletActivity.this, ChongZhiActivity.class));
                break;
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
        getAccount();
    }

    String totalMoney = "";

    private void getAccount() {
        Map maps = new HashMap();
        HttpMehtod.getInstance().userWollet(maps, new IdeaObserver<BaseDataBean<UserAccountDataBean>>(this, true) {

            @Override
            public void onSuccess(BaseDataBean<UserAccountDataBean> stringBaseDataBean) {

                if (stringBaseDataBean != null) {
                    totalMoney = stringBaseDataBean.getData().getLeft_coin();
                    myAccount.setText("¥：" + stringBaseDataBean.getData().getLeft_coin());
                }

            }

            @Override
            public void onFail(int errorCode) {

            }

        });
    }


}
